#!/bin/sh

# 加载工具类
. /etc/idnewnil/utils.sh

# 配置acme
DOMAIN=$(getstr '.domain')
uci set acme.@acme[0].account_email=$(getstr '.email')
uci del acme.example_wildcard
uci del acme.example
uci set acme.openwrt=cert
uci set acme.openwrt.enabled='0'
uci set acme.openwrt.use_staging='0'
uci set acme.openwrt.keylength='2048'
uci add_list acme.openwrt.domains=${DOMAIN}
uci add_list acme.openwrt.domains=$(getstr '.["domain.home"]')
uci set acme.openwrt.update_uhttpd='1'
uci set acme.openwrt.validation_method='dns'
uci set acme.openwrt.dns='dns_cf'
uci add_list acme.openwrt.credentials=CF_Key=$(getstr '.cf_key')
uci add_list acme.openwrt.credentials=CF_Email=$(getstr '.email')
uci set cert.acme=cert
uci set cert.acme.crt=/etc/acme/${DOMAIN}/${DOMAIN}.cer
uci set cert.acme.key=/etc/acme/${DOMAIN}/${DOMAIN}.key
uci commit
